package com.cdtye.itps.cms.service.cid;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.itps.cms.dao.cid.entity.JcjcUnitCidData;
import com.cdtye.itps.cms.dao.cid.vo.JcjcUnitCidDataVo;
import com.cdtye.itps.cms.mapper.cid.JcjcUnitCidDataMapper;
import com.cdtye.itps.cms.service.dept.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * 单元cid数据表 服务类
 * @author Jchen
 * @date 2021-09-24
 */
@Service
public class JcjcUnitCidDataService extends BaseService<JcjcUnitCidDataMapper, JcjcUnitCidData> {

    @Autowired
    private JcjcUnitCidDataMapper modelMapper;

    @Autowired
    private SysDeptService sysDeptService;

    /**
     * 分页查询，自定义sql语句
     * @param vo
     * @return
     */
    public IPage<Map<String,Object>> listPage(JcjcUnitCidDataVo vo){
        vo.setUnitDeptCode(sysDeptService.getUnitDeptCodeByLoginUser(vo.getUnitDeptCode()));
        return modelMapper.list(vo.page(), vo);
    }

    public JcjcUnitCidData queryByParams(String lineId, String directionId, Date taskDate, String beginMileage, String endMileage){
        QueryWrapper<JcjcUnitCidData> wrapper = new QueryWrapper<>();
        wrapper.eq("line_id",lineId);
        wrapper.eq("direction_id",directionId);
        wrapper.eq("task_date",taskDate);
        wrapper.eq("begin_mileage",beginMileage);
        wrapper.eq("end_mileage",endMileage);
        return modelMapper.selectOne(wrapper);
    }

}
